﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using ConsolidationTool.Common;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;
using ConsolidationTool.Common.Entities;

namespace ConsolidationTool.WebParts.Flash_Input.Flash_Input_HR.HRDisaplayForm
{
    public partial class HRDisaplayFormUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SPListItem item = Title.ListItem;

            string strmonth = Common.Utilities.GetItemValue(item, "Month");
            string stryear = Common.Utilities.GetItemValue(item, "Year");
            string strcoCd = Common.Utilities.GetItemValue(item, "CoCd");

            BindLastMonth(strcoCd, stryear, strmonth);

            string Headcount = FormField_Roquette_Headcount_month_end.ItemFieldValue.ToString();
            string Direct = FormFieldDirect.ItemFieldValue.ToString();
            string Indirect = FormFieldIndirect.ItemFieldValue.ToString();

            int value = Convert.ToInt32(Headcount) - Convert.ToInt32(Direct) - Convert.ToInt32(Indirect);

            LabelControl2.Text = value.ToString();
            if (value != 0)
            {
                Page.RegisterStartupScript("dd", "<script>document.controlCalcEqual=false;</script>");
            }
            else { 
                Page.RegisterStartupScript("dd", "<script>document.controlCalcEqual=true;</script>");
            }
        }

        void BindLastMonth(string coCd, string year, string month)
        {
            string y = year;
            string m = (Convert.ToInt32(month) - 1).ToString();
            if (Convert.ToInt32(month) == 1)
            {
                y = (Convert.ToInt32(year) - 1).ToString();
                m = "12";
            }
            SPListItem it = Common.BusinessService.GetItem(coCd, y, m, "HR");
            if (it != null)
            {
                Label_HR01010100.Text = Common.Utilities.GetItemValue(it, "HR01010100");
                Label_HR01010101.Text = Common.Utilities.GetItemValue(it, "HR01010101");
                Label_HR01010102.Text = Common.Utilities.GetItemValue(it, "HR01010102");
                Label_HR01010103.Text = Common.Utilities.GetItemValue(it, "HR01010103");
                Label_HR01010104.Text = Common.Utilities.GetItemValue(it, "HR01010104");
                Label_HR01010105.Text = Common.Utilities.GetItemValue(it, "HR01010105");
                Label_HR01010106.Text = Common.Utilities.GetItemValue(it, "HR01010106");
                Label_HR01010200.Text = Common.Utilities.GetItemValue(it, "HR01010200");
                Label_HR01010301.Text = Common.Utilities.GetItemValue(it, "HR01010301");
                Label_HR01010302.Text = Common.Utilities.GetItemValue(it, "HR01010302");
                Label_HR01020100.Text = Common.Utilities.GetItemValue(it, "HR01020100");
                Label_HR01020101.Text = Common.Utilities.GetItemValue(it, "HR01020101");
                Label_HR01020102.Text = Common.Utilities.GetItemValue(it, "HR01020102");
                Label_HR01020103.Text = Common.Utilities.GetItemValue(it, "HR01020103");
                Label_HR01020104.Text = Common.Utilities.GetItemValue(it, "HR01020104");
                Label_HR01020105.Text = Common.Utilities.GetItemValue(it, "HR01020105");
                Label_HR01020106.Text = Common.Utilities.GetItemValue(it, "HR01020106");
                Label_HR01020200.Text = Common.Utilities.GetItemValue(it, "HR01020200");
                Label_HR01030100.Text = Common.Utilities.GetItemValue(it, "HR01030100");
                Label_HR01030101.Text = Common.Utilities.GetItemValue(it, "HR01030101");
                Label_HR01030102.Text = Common.Utilities.GetItemValue(it, "HR01030102");
                Label_HR01040100.Text = Common.Utilities.GetItemValue(it, "HR01040100");
                Label_HR01040101.Text = Common.Utilities.GetItemValue(it, "HR01040101");
                Label_HR01040102.Text = Common.Utilities.GetItemValue(it, "HR01040102");
                Label_HR01050100.Text = Common.Utilities.GetItemValue(it, "HR01050100");
                Label_HR01060100.Text = Common.Utilities.GetItemValue(it, "HR01060100");
                Label_HR01060101.Text = Common.Utilities.GetItemValue(it, "HR01060101");
                Label_HR01060102.Text = Common.Utilities.GetItemValue(it, "HR01060102");
                Label_HR01070100.Text = Common.Utilities.GetItemValue(it, "HR01070100");
                Label_HR01070101.Text = Common.Utilities.GetItemValue(it, "HR01070101");
                Label_HR01070102.Text = Common.Utilities.GetItemValue(it, "HR01070102");
                Label_HR01080100.Text = Common.Utilities.GetItemValue(it, "HR01080100");
                Label_HR01090100.Text = Common.Utilities.GetItemValue(it, "HR01090100");
                Label_HR01020300.Text = Common.Utilities.GetItemValue(it, "HR01020300");

            }
            else
            {
                Label_HR01010100.Text = "0";
                Label_HR01010101.Text = "0";
                Label_HR01010102.Text = "0";
                Label_HR01010103.Text = "0";
                Label_HR01010104.Text = "0";
                Label_HR01010105.Text = "0";
                Label_HR01010106.Text = "0";
                Label_HR01010200.Text = "0";
                Label_HR01010301.Text = "0";
                Label_HR01010302.Text = "0";
                Label_HR01020100.Text = "0";
                Label_HR01020101.Text = "0";
                Label_HR01020102.Text = "0";
                Label_HR01020103.Text = "0";
                Label_HR01020104.Text = "0";
                Label_HR01020105.Text = "0";
                Label_HR01020106.Text = "0";
                Label_HR01020200.Text = "0";
                Label_HR01030100.Text = "0";
                Label_HR01030101.Text = "0";
                Label_HR01030102.Text = "0";
                Label_HR01040100.Text = "0";
                Label_HR01040101.Text = "0";
                Label_HR01040102.Text = "0";
                Label_HR01050100.Text = "0";
                Label_HR01060100.Text = "0";
                Label_HR01060101.Text = "0";
                Label_HR01060102.Text = "0";
                Label_HR01070100.Text = "0";
                Label_HR01070101.Text = "0";
                Label_HR01070102.Text = "0";
                Label_HR01080100.Text = "0";
                Label_HR01090100.Text = "0";
                Label_HR01020300.Text = "0";
            }
        }
    }
}
